package com.zzyk.main.mapper;

import com.zzyk.main.model.pojo.MaintenanceInfo;
import com.zzyk.main.model.vo.KeyValue;
import com.zzyk.main.model.vo.MaintenanceView;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Mapper
public interface MaintenanceInfoMapper {
    /**
     * delete by primary key
     *
     * @param id primaryKey
     * @return deleteCount
     */
    int deleteByPrimaryKey(Integer id);

    /**
     * insert record to table
     *
     * @param record the record
     * @return insert count
     */
    int insert(MaintenanceInfo record);

    /**
     * insert record to table selective
     *
     * @param record the record
     * @return insert count
     */
    int insertSelective(MaintenanceInfo record);

    /**
     * select by primary key
     *
     * @param id primary key
     * @return object by primary key
     */
    MaintenanceInfo selectByPrimaryKey(Integer id);

    /**
     * update record selective
     *
     * @param record the updated record
     * @return update count
     */
    int updateByPrimaryKeySelective(MaintenanceInfo record);

    /**
     * update record
     *
     * @param record the updated record
     * @return update count
     */
    int updateByPrimaryKey(MaintenanceInfo record);

    /**
     * 多条件查询
     *
     * @param beginTime
     * @param endTime
     * @param type
     * @param areaArr
     * @param deviceList
     * @return
     */
    List<MaintenanceInfo> selectAllByType(@Param("beginTime") Date beginTime, @Param("endTime") Date endTime, @Param("type") Integer type, @Param("enterprise") Integer enterprise, @Param("areaArr") String[] areaArr, @Param("name") String name, @Param("deviceTyp") Integer deviceTyp, @Param("deviceList") Integer[] deviceList);

    /**
     * 根据编号、类型来查询维保数据
     *
     * @param sn
     * @param type
     * @return
     */
    MaintenanceInfo selectOneBySnAndType(@Param("sn") String sn, @Param("type") Integer type);

    /**
     * 去查询根据设备编号查询最新的一条维保记录
     *
     * @param sn
     * @return
     */
    MaintenanceInfo selectByDeviceSnTopOne(@Param("sn") String sn);

    /**
     * 去查询根据设备编号查询最新的两条维保记录
     *
     * @param sn
     * @return
     */
    List<MaintenanceInfo> selectBySnTopTwo(@Param("sn") String sn);

    /**
     * 根据设备编号查询当天的维保次数
     *
     * @param sn
     * @return
     */
    Integer countToDayNumber(@Param("sn") String sn);

    KeyValue countConclusion(@Param("bDate") Date bDate, @Param("eDate") Date eDate, @Param("enterprise") Integer enterprise, @Param("type") Integer type, @Param("size") Integer size, @Param("deviceList") Integer[] deviceList);

    /**
     * 获取排行榜
     *
     * @param bDate
     * @param eDate
     * @param enterprise
     * @param deviceList
     * @return
     */
    List<MaintenanceView> selectFailureRanking(@Param("bDate") Date bDate, @Param("eDate") Date eDate, @Param("enterprise") Integer enterprise, @Param("deviceList") Integer[] deviceList);

    /**
     * 获取维保数据列表
     *
     * @param bDate
     * @param eDate
     * @param enterprise
     * @param deviceList
     * @return
     */
    List<MaintenanceInfo> selectInfoList(@Param("bDate") Date bDate, @Param("eDate") Date eDate, @Param("enterprise") Integer enterprise, @Param("deviceList") Integer[] deviceList);

    List<MaintenanceInfo> selectAllByParamApi(@Param("beginTime") Date beginTime, @Param("endTime") Date endTime, @Param("type") Integer type, @Param("enterprise") Integer enterprise, @Param("name") String name, @Param("deviceTyp") Integer deviceTyp, @Param("deviceList") Integer[] deviceList);

    List<Map<Object, Object>> countMaintenanceInfoByParam(@Param("bDate") Date bDate, @Param("eDate") Date eDate, @Param("type") Integer type, @Param("enterprise") Integer enterprise, @Param("areaArr") String[] areaArr, @Param("name") String name, @Param("deviceType") Integer deviceType, @Param("deviceList") Integer[] deviceList);

    List<Map<Object, Object>> countMaintenanceInfoByParamApi(@Param("bDate") Date bDate, @Param("eDate") Date eDate, @Param("type") Integer type, @Param("enterprise") Integer enterprise, @Param("name") String name, @Param("deviceType") Integer deviceType, @Param("deviceList") Integer[] deviceList);


}